package mock.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import mock.bo.CheckBalance;
import mock.bo.CheckBalanceImp;
import mock.bo.Logging;
import mock.bo.LoggingImp;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CheckBalanceAction extends ActionSupport{

	
	private Logging logBO = new LoggingImp();
	
	private CheckBalance bo = new CheckBalanceImp();
	
	private Map<String, Object> session = ActionContext.getContext().getSession();
	
	private String balance;
	
	
	
	public String getBalance() {
		return balance;
	}



	public void setBalance(String balance) {
		this.balance = balance;
	}



	/**
	 * check balance
	 */
	@Override
	public String execute() throws Exception {
		int atmID = (int) session.get("ATMID");
		String cardNo = (String)session.get("cardNo");
		double balance = bo.checkBalance(cardNo);
		setBalance(balance + ""); 
		logBO.logCheckBalance(atmID, cardNo, balance);
		return "success";
	}
	
}
